package com.example.blank700.musicplayer;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MusicPlayerActivity extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_music_player);

        Button btn_start_play=(Button)findViewById(R.id.btn_start_play);
        //btn_start_play.setOnClickListener(startIt);
        btn_start_play.setOnClickListener(this);
        Button btn_stop_play=(Button)findViewById(R.id.btn_stop_play);
        //btn_stop_play.setOnClickListener(stopIt);
        btn_stop_play.setOnClickListener(this);
    }

    public void onClick(View v){
        switch (v.getId()){
            case R.id.btn_start_play:
                Toast.makeText(MusicPlayerActivity.this,"播放音乐",
                        Toast.LENGTH_SHORT).show();
                startService(new Intent(MusicPlayerActivity.this,Music.class));
                break;
            case R.id.btn_stop_play:
                Toast.makeText(MusicPlayerActivity.this,"停止播放音乐",
                        Toast.LENGTH_SHORT).show();
                stopService(new Intent(MusicPlayerActivity.this,Music.class));
                finish();
                break;
        }
    }

/*    private View.OnClickListener startIt=new View.OnClickListener(){
        public void onClick(View v){
            startService(new Intent(MusicPlayerActivity.this,Music.class));
        }
    };

    private View.OnClickListener stopIt=new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            stopService(new Intent(MusicPlayerActivity.this,Music.class));
            finish();
        }
    };*/
}
